package com.ygqh.baby.service.impl;

import com.foxinmy.weixin4j.mp.model.User;
import com.ygqh.baby.ao.*;
import com.ygqh.baby.constant.Constant;
import com.ygqh.baby.constant.RedisConstant;
import com.ygqh.baby.mapper.YgUserMapper;
import com.ygqh.baby.model.YgUserModel;
import com.ygqh.baby.model.YgUserRecommendModel;
import com.ygqh.baby.model.YgUserStatisticsModel;
import com.ygqh.baby.po.YgUser;
import com.ygqh.baby.po.YgUserBalance;
import com.ygqh.baby.po.YgUserExample;
import com.ygqh.baby.po.YgUserExample.Criteria;
import com.ygqh.baby.po.YgUserMember;
import com.ygqh.baby.redis.RedisDao;
import com.ygqh.baby.service.*;
import com.ygqh.baby.utils.DateConvertUtils;
import com.ygqh.baby.utils.ShareCodeUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.crazycake.shiro.SerializeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.*;

@Service
public class YgUserServiceImpl implements YgUserService {

    @Autowired
    private YgUserMapper ygUserMapper;
    @Autowired
    private RedisDao redisDao;
    @Autowired
    private YgUserBalanceService userBalanceService;
    @Autowired
    private YgOrderService ygOrderService;
    @Autowired
    private YgReturnOrderService ygReturnOrderService;
    @Autowired
    private YgUserBalanceService ygUserBalanceService;
    @Autowired
    private YgUserMemberService ygUserMemberService;
    @Autowired
    private YgCardCouponDetailService ygCardCouponDetailService;
    @Autowired
    private YgCouponDetailService ygCouponDetailService;
    @Autowired
    private YgUserAddressService ygUserAddressService;
    @Autowired
    private YgUserLogService ygUserLogService;

    @Override
    public List<YgUser> find() {
        YgUserExample example = new YgUserExample();
        example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
        return ygUserMapper.selectByExample(example);
    }

    @Override
    public int findCount() {
        YgUserExample example = new YgUserExample();
        example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
        return ygUserMapper.countByExample(example);
    }

    @Override
    public List<YgUser> find(Date startDate, Date endDate) {
        YgUserExample example = new YgUserExample();
        Criteria criteria = example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
        if (startDate != null) {
            criteria.andCreateTimeGreaterThanOrEqualTo(startDate);
        }
        if (endDate != null) {
            criteria.andCreateTimeLessThan(endDate);
        }
        return ygUserMapper.selectByExample(example);
    }

    @Override
    public YgUser findById(Long id) {
        return ygUserMapper.selectByPrimaryKey(id);
    }

    @Override
    public int save(YgUser ygUser) {
        new PasswordHelper().encryptPassword(ygUser);
        System.err.println(ygUser.getPassword());
        System.err.println(ygUser.getSalt());
        return ygUserMapper.insertSelective(ygUser);
    }

    @Override
    public int update(YgUser ygUser) {
        if (StringUtils.isNotBlank(ygUser.getPassword())) {
            new PasswordHelper().encryptPassword(ygUser);
        }
        return ygUserMapper.updateByPrimaryKeySelective(ygUser);
    }

    @Override
    public ResultSet<YgUser> search(QueryInfo queryInfo, String phone, String nickName, Date startTime, Date endTime, String q, String fromCode,
                                    String groupTag, UserType userType) {
        List<YgUser> list = ygUserMapper.selectSuper(queryInfo, phone, nickName, startTime, endTime, q, fromCode, groupTag,
                userType == null ? null : userType.name());
        int count = ygUserMapper.countSuper(phone, nickName, startTime, endTime, q, fromCode, groupTag, userType == null ? null : userType.name());
        ResultSet<YgUser> resultSet = new ResultSet<YgUser>(count, list);
        return resultSet;
    }

    @Override
    public int deleteSoft(Long[] ids) {
        Assert.notEmpty(ids);
        YgUserExample example = new YgUserExample();
        example.createCriteria().andIdIn(Arrays.asList(ids)).andStatusEqualTo(DataStatus.Valid.name());
        YgUser record = new YgUser();
        record.setStatus(DataStatus.Delete);
        record.setUpdateTime(new Date());
        return ygUserMapper.updateByExampleSelective(record, example);
    }

    @Override
    public int deleteSoft(Long id) {
        return this.deleteSoft(new Long[]{id});
    }

    @Override
    public int saveOrUpdate(YgUser ygUser) {
        int r = 0;
        if (ygUser.getId() != null) {
            r = this.update(ygUser);
        } else {
            r = this.save(ygUser);
        }
        return r;
    }

    @Override
    public YgUser findByUserName(String username) {
        YgUserExample example = new YgUserExample();
        example.createCriteria().andUserNameEqualTo(username).andStatusEqualTo("Valid");
        List<YgUser> users = null;
        try {
            users = ygUserMapper.selectByExample(example);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        if (null != users && !users.isEmpty()) {
            return users.get(0);
        }
        return null;
    }

    @Override
    public void saveValidateCodeToRedis(String username, ValidateCode validateCode, int expire) {
        redisDao.set((RedisConstant.MOBILE_SMS_VALIDATE_CODE + username).getBytes(), SerializeUtils.serialize(validateCode), expire);
    }

    @Override
    public ValidateCode selectValidateCodeToRedis(String username) {
        byte[] b = redisDao.get((RedisConstant.MOBILE_SMS_VALIDATE_CODE + username).getBytes());
        return (ValidateCode) SerializeUtils.deserialize(b);
    }

    @Override
    public int updateUserInfo(Long userId, String userLogo, String nickName, Integer babyGender, Date babyBirthday) {
        YgUser user = new YgUser();
        user.setId(userId);
        user.setNickName(nickName);
        user.setHeadImageUrl(userLogo);
        user.setBabyGender(babyGender);
        user.setBabyBirthday(babyBirthday);
        return ygUserMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public ResultSet<YgUserStatisticsModel> searchUserStatistics(QueryInfo queryInfo, Date startDate, Date endDate, String sourceCode, String q) {
        List<YgUserStatisticsModel> list = ygUserMapper.selectUserStatistics(queryInfo, startDate, endDate, sourceCode, q);
        int row = ygUserMapper.countUserStatistics(startDate, endDate, sourceCode, q);
        return new ResultSet<YgUserStatisticsModel>(row, list);
    }

    @Override
    public YgUserModel findUserInfo(Long userId) {
        return ygUserMapper.selectUserInfo(userId);
    }

    @Override
    public int bindingOpenId(Long userId, String openid, String smallOpenId, String unionId) {
        YgUser ygUser = new YgUser();
        ygUser.setId(userId);
        ygUser.setOpenId(openid);
        ygUser.setUuid(unionId);
        ygUser.setSmallOpenId(smallOpenId);

        return ygUserMapper.updateByPrimaryKeySelective(ygUser);
    }

    @Override
    public YgUser findByOpenId(String openId) {
        YgUserExample example = new YgUserExample();
        example.createCriteria().andStatusEqualTo(DataStatus.Valid.name()).andOpenIdEqualTo(openId);
        List<YgUser> users = ygUserMapper.selectByExample(example);
        if (!users.isEmpty()) {
            return users.get(0);
        }
        return null;
    }

    @Override
    public List<YgUserStatisticsModel> findUserStatistics(QueryInfo queryInfo, Date startDate, Date endDate, String sourceCode, String q) {
        return ygUserMapper.selectUserStatistics(queryInfo, startDate, endDate, sourceCode, q);
    }

    @Override
    public List<YgUserStatisticsModel> findUserGrouBySourceCode(String sourceCode) {
        return ygUserMapper.selectUserGrouBySourceCode(sourceCode);
    }

    @Override
    public int updateUserInfo(YgUser ygUser) {
        return ygUserMapper.updateByPrimaryKeySelective(ygUser);
    }

    @Override
    public List<Map<String, Object>> findUserStatisticsLM(Date startDate, Date endDate, String sourceCode) {
        return ygUserMapper.selectUserStatisticsLM(startDate, endDate, sourceCode);
    }

    @Override
    public Boolean isGuide(Long userId) {
        Boolean flag = ygUserMapper.isGuide(userId);
        ygUserMapper.updateGuide(userId);
        return flag;
    }

    @Override
    public YgUser findBySourceCode(String sourceCode) {
        if (StringUtils.isEmpty(sourceCode)) {
            return null;
        }
        YgUserExample example = new YgUserExample();
        example.createCriteria().andSourceCodeEqualTo(sourceCode).andStatusEqualTo(DataStatus.Valid.name());
        List<YgUser> users = ygUserMapper.selectByExample(example);
        if (null != users && !users.isEmpty()) {
            return users.get(0);
        }
        return null;
    }

    @Override
    public Boolean isNewCustom(Long userId) {
        return isNewCustom(userId, Constant.YIIGOO_PLATFORM_NO);
    }

    @Override
    public Boolean isNewCustom(Long userId, String platformNo) {
        Date startTime = null;
        if (Constant.YIJIADIAN_PLATFORM_NO.equals(platformNo)) {
            try {
                startTime = DateUtils.parseDate("2019-04-15", "yyyy-MM-dd");
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return isNewCustom(userId, platformNo, startTime);
    }

    @Override
    public int updateUserBySourceCode(YgUser user) {
        YgUserExample example = new YgUserExample();
        example.createCriteria().andUserNameEqualTo(user.getUserName()).andStatusEqualTo(DataStatus.Valid.name());
        return ygUserMapper.updateByExampleSelective(user, example);
    }

    @Override
    public int becomeSeller(Long userId) {
        YgUser user = this.findById(userId);
        user.setIsSeller(true);
        return ygUserMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public Long findPaidUsersCount(Date startTime, Date endTime) {
        return ygUserMapper.findPaidUsersCount(startTime, endTime);
    }

    @Override
    public Long findPaidNewUsersCount(Date startTime, Date endTime) {
        return ygUserMapper.findPaidNewUsersCount(startTime, endTime);
    }

    @Override
    public YgUser findByUuid(String uuid) {
        YgUserExample example = new YgUserExample();
        example.createCriteria().andStatusEqualTo(DataStatus.Valid.name()).andUuidEqualTo(uuid);
        List<YgUser> users = ygUserMapper.selectByExample(example);
        if (!users.isEmpty()) {
            return users.get(0);
        }
        return null;
    }

    @Override
    public YgUser register(String username, String password, String fromCode, String defaultHeadUrl, String defaultNickNamePrefix) {
        YgUser ygUser = new YgUser();
        ygUser.setUserName(username);
        ygUser.setPassword(password);
        ygUser.setTelPhone(username);
        ygUser.setFromCode(fromCode);
        ygUser.setSourceCode(username);
        ygUser.setBabyBirthday(null);
        ygUser.setBabyGender(null);
        ygUser.setGender(null);
        ygUser.setHeadImageUrl(defaultHeadUrl);
        if (username.length() >= 7) {
            ygUser.setNickName(defaultNickNamePrefix + username.substring(7, 11));
        }
        ygUser.setCreateTime(new Date());
        this.save(ygUser);

        YgUserBalance userBalance = new YgUserBalance();
        userBalance.setBalancePrice(new BigDecimal(0));
        userBalance.setCreateTime(new Date());
        userBalance.setFreezePrice(new BigDecimal(0));
        userBalance.setPreincomePrice(new BigDecimal(0));
        userBalance.setUserId(ygUser.getId());
        userBalance.setWithdrawPrice(new BigDecimal(0));
        userBalanceService.save(userBalance);

        return ygUser;
    }

    @Override
    public int repairUnionIdBatch(List<User> users) {

        return ygUserMapper.repairUnionIdBatch(users);
    }

    @Override
    public List<String> findOpenIds(Long start, Long end) {
        return ygUserMapper.findOpenIds(start, end);
    }

    @Override
    public List<YgUser> findUsersByUserNames(List<String> usernames) {
        System.err.println("user=" + usernames);
        return ygUserMapper.findUsersByUserNames(usernames);
    }

    @Override
    public int findUserRecommendCount(String fromCode, String groupTag) {
        return ygUserMapper.selectUserRecommendCount(fromCode, groupTag);
    }

    @Override
    public List<YgUserRecommendModel> findUserRecommend(QueryInfo queryInfo, String fromCode, String groupTag) {

        return ygUserMapper.selectUserRecommend(queryInfo, fromCode, groupTag);
    }

    @Override
    public int findCountOpen(Long couponId) {
        return ygUserMapper.selectOpenIdByCouponIdCount(couponId);
    }

    @Override
    public List<YgUser> selectCountOpen(QueryInfo queryInfo, Long couponId) {
        return ygUserMapper.selectOpenIdByCouponIdList(queryInfo, couponId);
    }

    @Override
    public List<YgUser> selectUserByPage(QueryInfo queryInfo) {

        YgUserExample example = new YgUserExample();
        example.createCriteria().andStatusEqualTo(DataStatus.Valid.name()).andOpenIdIsNotNull().andIsSubscribeEqualTo(true);

        List<YgUser> list = ygUserMapper.selectByExample(example);
        return list;
    }

    @Override
    public int findCountById() {
        YgUserExample example = new YgUserExample();
        example.createCriteria().andStatusEqualTo(DataStatus.Valid.name()).andOpenIdIsNotNull().andIdLessThan(124590L);

        return ygUserMapper.countByExample(example);
    }

    @Override
    public YgUser findByUserName(String username, UserType userType) {
        YgUserExample example = new YgUserExample();
        example.createCriteria().andUserNameEqualTo(username).andStatusEqualTo("Valid").andUserTypeEqualTo(userType.name());
        List<YgUser> users = null;
        try {
            users = ygUserMapper.selectByExample(example);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        if (null != users && !users.isEmpty()) {
            return users.get(0);
        }
        return null;
    }

    @Override
    public int findNewCountByFromCode(String[] sourceCodes, Date startDate, Date endDate) {
        YgUserExample example = new YgUserExample();
        example.createCriteria().andStatusEqualTo(DataStatus.Valid.name()).andCreateTimeBetween(startDate, endDate).andFromCodeIn(Arrays.asList(sourceCodes));
        return ygUserMapper.countByExample(example);
    }

    @Override
    public int updateSubscribeStatus(String openId, Boolean isSubscribe) {
        return ygUserMapper.updateSubscribeStatus(openId, isSubscribe);
    }

    @Override
    public int updateSubscribeStatusBatch(List<String> openIds, boolean b) {
        return ygUserMapper.updateSubscribeStatusBatch(openIds, b);
    }

    @Override
    public YgUser findLastUser() {
        return ygUserMapper.selectLastUser();
    }

    @Override
    public int updateUserLevel(Long userId, int level, Date birthDay) {
        YgUser record = new YgUser();
        record.setId(userId);
        record.setLevel(level);
        record.setBabyBirthday(birthDay);
        record.setUpdateTime(new Date());
        return ygUserMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public Boolean isVip(Long userId) {

        return ygUserMemberService.isVip(userId);
    }

    @Override
    public List<YgUser> send11buquan(Boolean isSubscribe) {
        return ygUserMapper.send11buquan(isSubscribe);
    }

    @Override
    public Boolean isUserAgent(Long userId) {
        YgUserExample example = new YgUserExample();
        example.createCriteria().andIdEqualTo(userId).andStatusEqualTo(DataStatus.Valid.name()).andUserTypeEqualTo(UserType.UserAgent.name());
        List<YgUser> list = ygUserMapper.selectByExample(example);
        if (!CollectionUtils.isEmpty(list)) {
            return true;
        }
        return false;
    }

    @Override
    public Boolean isUserGroup(Long userId) {
        YgUserExample example = new YgUserExample();
        example.createCriteria().andIdEqualTo(userId).andStatusEqualTo(DataStatus.Valid.name()).andUserTypeEqualTo(UserType.Group.name());
        List<YgUser> list = ygUserMapper.selectByExample(example);
        if (!CollectionUtils.isEmpty(list)) {
            return true;
        }
        return false;

    }

    @Override
    public YgUser findGroupHead(String groupTag) {

        if (StringUtils.isBlank(groupTag)) {
            return null;
        }
        YgUserExample example = new YgUserExample();
        example.createCriteria().andGroupTagEqualTo(groupTag).andStatusEqualTo(DataStatus.Valid.name()).andUserTypeEqualTo(UserType.Group.name());
        List<YgUser> list = ygUserMapper.selectByExample(example);
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        return list.get(0);
    }

    @Override
    public List<YgUser> findGroupUser(String groupTag, Boolean exitGroupHead) {
        if (StringUtils.isBlank(groupTag)) {
            return null;
        }
        YgUserExample example = new YgUserExample();
        Criteria criteria = example.createCriteria().andGroupTagEqualTo(groupTag).andStatusEqualTo(DataStatus.Valid.name());
        if (!exitGroupHead) {
            criteria.andUserTypeEqualTo(UserType.Ordinary.name());
        }
        List<YgUser> list = ygUserMapper.selectByExample(example);
        return list;
    }

    @Override
    public int updateAgentToCancelByUserId(Long userId) {
        return ygUserMapper.updateAgentToCancel(userId);
    }

    @Override
    public Boolean isNewCustom(Long userId, Long orderId) {
        int row = ygUserMapper.isNewCustomExcludeOrderId(userId, orderId);
        if (row > 0) {
            return false;
        }
        return true;
    }

    @Override
    public Message transferData(YgUser sourceUser, YgUser targetUser) {
        if (sourceUser.getId().equals(targetUser.getId())) {
            return Message.error("不能关联自己", null);
        }
        // 1转移订单
        ygOrderService.transferOrder(sourceUser.getId(), targetUser.getId());
        // 2 转移退货单
        ygReturnOrderService.transferReturnOrder(sourceUser.getId(), targetUser.getId());
        // 3.转移成长基金
        ygUserBalanceService.transferBalance(sourceUser.getId(), targetUser.getId());
        // 4. 卡券转移
        ygCardCouponDetailService.transferCardCoupon(sourceUser.getId(), targetUser.getId());
        // 5 优惠券转移
        ygCouponDetailService.transferCoupon(sourceUser.getId(), targetUser.getId());

        // 6.收货地址转移
        ygUserAddressService.transferUserAddr(sourceUser.getId(), targetUser.getId());

        int deleteSoft = this.deleteSoft(sourceUser.getId());
        ygUserLogService.addUserLog(targetUser.getId(), "合并用户", "合并用户【" + sourceUser.getId() + "】的订单，成长金，优惠券，卡券，收货地址。", sourceUser.getNickName(),
                sourceUser.getUserName());

        // 4 。女王转移
        // if(sourceUser.getLevel()==10){
        // ygUserMemberService.transferMember(sourceUser, targetUser);
        // }
        // 5 耕耘成果转移
        // 7 优惠券转移
        // 8 用户收货地址
        // 9 用户砍价进度转移
        // 10 代理转移
        // 11 银行账号转移

        return Message.success(deleteSoft);
    }

    @Override
    public List<YgUser> findByUserType(UserType userType) {
        YgUserExample example = new YgUserExample();
        example.createCriteria().andStatusEqualTo(DataStatus.Valid.name()).andUserTypeEqualTo(userType.name());
        return ygUserMapper.selectByExample(example);
    }

    @Override
    public int updateUserType(UserType userType, Long id) {
        if (userType == null || id == null) {
            return 0;
        }
        YgUser user = new YgUser();
        user.setId(id);
        user.setUserType(UserType.UserAgent);
        user.setUpdateTime(new Date());
        return this.updateUserInfo(user);
    }

    @Override
    public Boolean isVipNew(Long userId) {
        return isVipNew(userId, Constant.YIIGOO_PLATFORM_NO);
    }

    @Override
    public Boolean isVipNew(Long userId, String platformNo) {
        if (Constant.YIJIADIAN_PLATFORM_NO.equals(platformNo)) {
            return false;
        }
        YgUserMember userMember = ygUserMemberService.findByUserId(userId);
        Date today = DateConvertUtils.getDateStart(new Date());
        return userMember != null && userMember.getMemberEndTime().compareTo(today) >= 0;
    }

    @Override
    public List<YgUser> findByLevel(Integer level) {
        if (level == null) {
            level = 1;
        }
        YgUserExample example = new YgUserExample();
        example.createCriteria().andStatusEqualTo(DataStatus.Valid.name()).andLevelEqualTo(level);
        return ygUserMapper.selectByExample(example);
    }

    @Override
    public YgUser findOpenId(Long userId) {
        return ygUserMapper.selectOpenId(userId);
    }

    @Override
    public int updateWxData(Long userId, String openId, String smallOpenId, String uuid, String nickName, String headImageUrl, String fromCode) {
        YgUser user = new YgUser();
        user.setId(userId);
        user.setOpenId(openId);
        user.setSmallOpenId(smallOpenId);
        user.setUuid(uuid);
        user.setNickName(nickName);
        user.setHeadImageUrl(headImageUrl);
        user.setFromCode(fromCode);
        return this.updateUserInfo(user);
    }

    @Override
    public List<YgUser> selectNewUserList(Date startDate) {
        return ygUserMapper.selectNewUserList(startDate);
    }

    @Override
    public List<YgUser> findOpenIdsByUnUsedCouponId(List<Long> couponIdList) {
        return findOpenIdsByUnUsedCouponId(couponIdList, null);
    }

    @Override
    public List<YgUser> findOpenIdsByUnUsedCouponId(List<Long> couponIdList, Date createStartTime) {
        return ygUserMapper.selectOpenIdsByUnUsedCouponId(couponIdList, createStartTime);
    }

    @Override
    public List<YgUser> findOpenIdByNotOrderWithOrderTime(Date startDate) {
        return ygUserMapper.selectOpenIdByNotOrderWithOrderTime(startDate);
    }

    @Override
    public List<YgUser> findOpenIdByNotOrderWithRegisterTime(Date startDate) {
        return ygUserMapper.selectOpenIdByNotOrderWithRegisterTime(startDate);
    }

    @Override
    public List<YgUser> findWithField(String field, Integer level, boolean onlyNew, Date startDate, String... userType) {
        return findWithField(field, level, onlyNew, false, false, startDate, userType);
    }

    @Override
    public List<YgUser> findWithField(String field, Integer level, boolean onlyNew, boolean isSubscribe,
                                      boolean hasOpenId, Date startDate, String... userType) {
        if (StringUtils.isBlank(field) || (field.toLowerCase().contains("select"))
                || (field.toLowerCase().contains("from"))) {
            return Collections.emptyList();
        }
        return ygUserMapper.selectWithField(field, level, onlyNew, isSubscribe, hasOpenId, startDate,
                userType != null && userType.length == 0 ? null : userType);
    }

    @Override
    public List<YgUser> findOpenIds(List<Long> idList) {
        return ygUserMapper.selectOpenIds(CollectionUtils.isEmpty(idList) ? null : idList);
    }

    @Override
    public List<String> findOpenIdByNotRegister() {
        return ygUserMapper.selectOpenIdByNotRegister();
    }

    @Override
    public Boolean isNewCustom(Long userId, String platformNo, Date startTime) {
        Assert.notNull(userId, "param userId can not be null");
        int row = ygUserMapper.isNewCustom(userId, platformNo, startTime);
        return row <= 0;
    }

    @Override
    public Boolean isNewCustomByYijiadian(Long userId) {
        return isNewCustom(userId, Constant.YIJIADIAN_PLATFORM_NO);
    }

    @Override
    public String getSourceCodeByShareCode(String shareCode) {
        try {
            long id = ShareCodeUtil.codeToId(shareCode);
            YgUser fromUser = this.findById(id);
            if (fromUser != null) {
                shareCode = fromUser.getSourceCode();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return shareCode;
    }

    @Override
    public int updateFromCode(String oldFromCode, String newFromCode) {
        if (StringUtils.isBlank(oldFromCode)) {
            return 0;
        }
        YgUserExample example = new YgUserExample();
        example.createCriteria().andFromCodeEqualTo(oldFromCode).andStatusEqualTo(DataStatus.Valid.name());
        YgUser record = new YgUser();
        record.setFromCode(newFromCode);
        record.setUpdateTime(new Date());
        return ygUserMapper.updateByExampleSelective(record, example);
    }
}
